import 'package:flutter/material.dart';

void main() {
  // 1. 运行应用程序。
  runApp(const MaterialApp(
    home: Main(),
  ));
}

class Main extends StatelessWidget {
  const Main({super.key});

  static const List myColors = [
    Colors.red,
    Colors.yellow,
    Colors.green,
    Colors.orange,
    Colors.purple,
    Colors.teal,
    Colors.cyan,
    Colors.lightBlue,
    Colors.blue,
    Colors.deepPurple,
    Colors.brown,
    Colors.grey,
    Colors.black,
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text(
          'ListView组件 - 列表循环基础',
          style: TextStyle(color: Colors.white),
        ),
        backgroundColor: Colors.purple,
      ),
      body: ListView.separated(
        itemBuilder: (BuildContext context, int index) {
          return Container(
            height: 50,
            color: myColors[index],
            child: Text('${myColors[index]}'),
          );
        },
        separatorBuilder: (BuildContext context, int index) {
          return Container(
            height: 2,
            color: myColors[index],
            margin: const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
          );
        },
        itemCount: myColors.length,
      ),
    );
  }
}
